<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>

    <style>
        .el-table .warning-row {
            background: oldlace;
        }

        .el-table .success-row {
            background: #f0f9eb;
        }
    </style>

</head>
<body>

<div id="app">


    <script src="../js/Vue/vue.js"></script>
    <script src="../element-ui/lib/index.js"></script>
    <link rel="stylesheet" href="../element-ui/lib/theme-chalk/index.css">
    <script src="../js/Axios/axios-0.18.0.js"></script>


    <el-form :inline="true" :model="formInline" class="demo-form-inline">
        <el-form-item label="用户的手机号码">
            <el-input v-model="formInline.businessPhone" placeholder="用户手机号码"></el-input>
        </el-form-item>
        <el-form-item label="状态:">
            <el-select v-model="formInline.status" placeholder="请选择要查找的状态">
                <el-option label="全部" value="3"></el-option>
                <el-option label="申请中" value="2"></el-option>
                <el-option label="正常" value="1"></el-option>
                <el-option label="已禁用" value="0"></el-option>
            </el-select>
        </el-form-item>
        <el-form-item>
            <el-button type="primary" @click="onSubmit">查询</el-button>
        </el-form-item>
    </el-form>


    <template>
        <el-table
                :data="business"
                style="width: 100%"
                :row-class-name="tableRowClassName">
            <el-table-column
                    prop="id"
                    label="商家 id"
                    width="180">
            </el-table-column>
            <el-table-column
                    prop="phone"
                    label="商家电话"
                    width="180">
            </el-table-column>
            <el-table-column
                    prop="status"
                    label="商家状态">
                <template slot-scope="scope">

                    {{ scope.row.status == '0' ? '已禁用' : '' }}
                    {{ scope.row.status == '1' ? '正常' : '' }}
                    {{ scope.row.status == '2' ? '申请中' : '' }}
                </template>
            </el-table-column>
            <el-table-column
                    label="操作">
                <template slot-scope="scope">

                    <el-button type="primary" v-if="scope.row.status != 1 "
                               @click="enable(scope.row)">启用
                    </el-button>
                    <el-button type="primary" v-if="scope.row.status != 0" style="background-color: #dd6161"
                               @click="disable(scope.row)">禁用
                    </el-button>
                </template>
            </el-table-column>



        </el-table>
    </template>


</div>


<script>

    new Vue({

        el: "#app",
        data() {
            return {
                formInline: {
                    businessPhone: '',
                    status: '3'
                },


                business: [{
                    id: '1584882283090817025',
                    phone: '13112345678',
                    status: '1',
                }]


            }
        },
        methods: {
            // 表单的提交事件，查询的功能
            onSubmit() {
                console.log('submit!');

                alert(this.formInline.businessPhone + "     " + this.formInline.status)

                if (this.formInline.businessPhone == ""){
                    this.formInline.businessPhone = -1
                }

                var _this = this;
                axios({
                    method:"get",
                    url: "/employee/getBusiness?" +
                        "businessPhone=" + this.formInline.businessPhone +
                        "&status=" + this.formInline.status
                }).then(function (resp){

                    if (resp.data.code == 1){
                        _this.business = resp.data.data;
                        /*                    this.$message({
                                                type: 'success',
                                                message: '查询成功'
                                            });*/
                    } else {
                        this.$message({
                            showClose: true,
                            message: '查询失败,',
                            type: 'error'
                        });

                    }
                });



            },

            // 禁用
            disable(row){


                let _this = this;
                this.$confirm('此操作将会取消该商家的所有订单, 并且禁用该账号, 是否继续禁用?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {

                    axios({
                        method:"put",
                        url: "/employee/updateBusiness",
                        data: {"id":row.id, "status":0, "phone":row.phone}
                    }).then(function (resp){
                        _this.onSubmit();
                        this.$message({
                            type: 'success',
                            message: resp.date.msg
                        });
                    })
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消停售'
                    });
                });
           },

            // 启用
            enable(row){

                let _this = this;
                this.$confirm('此操作将会启用用该账号, 是否继续启用?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {

                    axios({
                        method:"put",
                        url: "/employee/updateBusiness",
                        data: {"id":row.id, "status":1, "phone":row.phone}
                    }).then(function (resp){
                        _this.onSubmit();
                        this.$message({
                            type: 'success',
                            message: resp.date.msg
                        });
                    })
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消停售'
                    });
                });

            },











            tableRowClassName({row, rowIndex}) {
                if (rowIndex % 2 === 1) {
                    return 'warning-row';
                } else if (rowIndex % 2 === 0) {
                    return 'success-row';
                }
                return '';
            }


        },
        /* 初始化数据， */
        created() {
            this.onSubmit();

        }

    })
</script>


</body>
</html>